using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Experiment;

public class UCTrackBar : UserControl
{
	private EventHandler _valueChangeEvent;

	private double _minValue = 1.0;

	private double _maxValue = 10.0;

	private double _labelText = 0.0;

	private IContainer components = null;

	private TrackBar trackBar;

	private Label label;

	private Label label1;

	[Description("滚动改变事件")]
	[Category("自定义")]
	public EventHandler ValueChangeEvent
	{
		get
		{
			return _valueChangeEvent;
		}
		set
		{
			_valueChangeEvent = (EventHandler)Delegate.Combine(_valueChangeEvent, value);
		}
	}

	public double MinValue
	{
		get
		{
			return _minValue;
		}
		set
		{
			_minValue = value;
			label.Text = value.ToString("f4");
		}
	}

	public double MaxValue
	{
		get
		{
			return _maxValue;
		}
		set
		{
			_maxValue = value;
		}
	}

	public double LabelText
	{
		get
		{
			return _labelText;
		}
		set
		{
			_labelText = value;
			label.Text = value.ToString("f4");
		}
	}

	public UCTrackBar()
	{
		InitializeComponent();
		trackBar_MouseCaptureChanged(null, null);
	}

	private void trackBar_MouseCaptureChanged(object sender, EventArgs e)
	{
		LabelText = (_maxValue - _minValue) / 10.0 * (double)(trackBar.Value - 1) + _minValue;
		if (trackBar.Value == 1)
		{
			LabelText = _minValue;
		}
		if (trackBar.Value == 10)
		{
			LabelText = _maxValue;
		}
	}

	private void trackBar_MouseDown(object sender, MouseEventArgs e)
	{
		trackBar_MouseCaptureChanged(sender, e);
	}

	private void trackBar_MouseHover(object sender, EventArgs e)
	{
		trackBar_MouseCaptureChanged(sender, e);
	}

	private void trackBar_Scroll(object sender, EventArgs e)
	{
		trackBar_MouseCaptureChanged(sender, e);
	}

	private void trackBar_ValueChanged(object sender, EventArgs e)
	{
		if (ValueChangeEvent != null)
		{
			_valueChangeEvent(sender, e);
		}
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.trackBar = new System.Windows.Forms.TrackBar();
		this.label = new System.Windows.Forms.Label();
		this.label1 = new System.Windows.Forms.Label();
		((System.ComponentModel.ISupportInitialize)this.trackBar).BeginInit();
		base.SuspendLayout();
		this.trackBar.Location = new System.Drawing.Point(18, 36);
		this.trackBar.Maximum = 100;
		this.trackBar.Minimum = 1;
		this.trackBar.Name = "trackBar";
		this.trackBar.Size = new System.Drawing.Size(345, 56);
		this.trackBar.TabIndex = 0;
		this.trackBar.Value = 1;
		this.trackBar.Scroll += new System.EventHandler(trackBar_Scroll);
		this.trackBar.ValueChanged += new System.EventHandler(trackBar_ValueChanged);
		this.trackBar.MouseDown += new System.Windows.Forms.MouseEventHandler(trackBar_MouseDown);
		this.trackBar.MouseHover += new System.EventHandler(trackBar_MouseHover);
		this.label.AutoSize = true;
		this.label.Location = new System.Drawing.Point(15, 9);
		this.label.Name = "label";
		this.label.Size = new System.Drawing.Size(55, 15);
		this.label.TabIndex = 1;
		this.label.Text = "label1";
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(27, 76);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(15, 15);
		this.label1.TabIndex = 2;
		this.label1.Text = "1";
		base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 15f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.Controls.Add(this.label1);
		base.Controls.Add(this.label);
		base.Controls.Add(this.trackBar);
		base.Name = "UCTrackBar";
		base.Size = new System.Drawing.Size(444, 139);
		((System.ComponentModel.ISupportInitialize)this.trackBar).EndInit();
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
